#include <iostream>
using namespace std;

char result[1010];
int num=0;
int main()
{
	int t;
	while(cin>>t){
		for(int i=0;i<t;i++){
			string src;
			cin>>src;
			int max=0;
			char max_char=src[0];
			for(int i=0;i<src.length();i++){
				int count=0;
				if(src[i]=='*') continue;
				//src[i]='*';
				count=1;
				for(int j=i+1;j<src.length();j++){
					if(src[j]==src[i]){
						src[j]='*';
						count++;
					}
				}
				if(count>max){
					max=count;
					max_char=src[i];
				}
				else if(count==max){
					if(max_char>src[i]){
						max_char=src[i];
					}
				}
			}
			result[num]=max_char;
			num++;
		}
		for(int j=0;j<t;j++){
			cout<<result[j]<<endl;
		}
		num=0;
	}
}
